<template>
  <div class="table-page-search-wrapper">
    <el-form :model="searchForm" ref="searchForm" label-width="100px" class="demo-ruleForm">
      <el-row :gutter="10">
        <div v-show="keyName === '1'">
          <el-col :md="8" :sm="12" :xs="24">
            <el-form-item label="选择日期:">
              <a-range-picker
                v-model="searchForm.zdsj"
                show-time
                style="width: 100%"
                format="YYYY-MM-DD HH:mm:ss"
                @change="cxsjChange"
              />
            </el-form-item>
          </el-col>
          <el-col :md="5" :sm="12" :xs="24">
            <el-form-item label="销售渠道:">
              <a-select v-model="searchForm.orderSource" placeholder="请选择销售渠道" style="width: 100%">
                <a-select-option v-for="item in qudaoList" :key="item.value" :value="item.value">{{
                  item.label
                }}</a-select-option>
              </a-select>
            </el-form-item>
          </el-col>
        </div>
        <div v-show="keyName === '2'">
          <el-col :md="8" :sm="12" :xs="24">
            <el-form-item label="商品类目:">
              <a-cascader
                :options="categoryIdList"
                v-model="pids"
                change-on-select
                placeholder="请选择商品类目"
              ></a-cascader>
            </el-form-item>
          </el-col>
        </div>
        <el-col :md="6" :sm="12" :xs="24">
          <div style="margin-left: 30px">
            <a-button type="primary" icon="search" @click="searchAction()">查询</a-button>
            <a-button icon="delete" @click="resetSearch()" style="margin-left: 8px">重置</a-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { platformgoodscategory } from '@/api/shop/procurement.js'
export default {
  name: 'search',
  props: ['keyName'],
  data() {
    return {
      qudaoList: [
        {
          label: '小程序',
          value: '00',
        },
        {
          label: 'APP',
          value: '01',
        },
        {
          label: '线下',
          value: '02',
        },
      ], //销售渠道
      searchForm: {},
      categoryIdList: [],
      pids: [],
    }
  },
  mounted() {
    this.getDic()
  },
  methods: {
    searchAction() {
      //执行搜索
      if (this.pids) {
        if (this.pids.length > 1) {
          //商品类目
          this.searchForm.categoryId = this.pids[1]
          this.searchForm.pid = this.pids[0]
        } else {
          this.searchForm.categoryId = this.pids[0]
          this.searchForm.pid = this.pids[0]
        }
      }
      this.$emit('search')
    },
    resetSearch() {
      this.searchForm = {}
      this.pids = []
      this.$emit('resetSearch')
    },
    getSearchForm() {
      //获取高级搜索条件
      return {
        ...this.searchForm,
      }
    },
    cxsjChange(e) {
      var timeList = [this.formDate(e[0]._d), this.formDate(e[1]._d)]
      this.searchForm.startTime = timeList[0]
      this.searchForm.endTime = timeList[1]
    },
    getDic() {
      platformgoodscategory({ businessType: '' }).then((val) => {
        //商品类目
        let data = val.data
        console.log(data)
        this.categoryIdList = data.map((item) => {
          return {
            value: item.categoryId,
            label: item.categoryName,
            children: item.children.map((items) => {
              return {
                value: items.categoryId,
                label: items.categoryName,
              }
            }),
          }
        })
      })
    },
  },
}
</script>


<style lang="less">
</style>>
